/**
 * Created with JetBrains WebStorm.
 * User: sparks345
 * Date: 12-6-9
 * Time: 下午9:20
 * To change this template use File | Settings | File Templates.
 */

QZONE = window.QZONE || {};

QZONE.Finder = QZONE.Finder || {};

QZONE.Finder.Loader = QZONE.Finder.Loader || function() {
	var component = [
		'<div class="popup_qzonefinder" id="_finder_container">',
			'<div class="popup_qzonefinder_hd">',
				'<h2>Qzone Finder</h2>',
				'<a class="popup_qzonefinder_close" href="javascript:QZONE.Finder.Loader.hide();" title="关闭">Χ</a>',
			'</div>',
			'<div class="popup_qzonefinder_cont">',
				'<div class="qzmod_itemlist_inner">',
					'<div class="scroll" id="finder_list_container">',
					'</div>',
				'</div>',
				'<div class="qzmod_itempage" id="nav"></div>',
				'<div class="qzmod_itemsubpage"><a id="_finder_prev" class="prev" href="javascript:;">&lt;</a><a id="_finder_next" class="next" href="javascript:;">&gt;</a></div>',
			'</div>',
//			'<div class="popup_qzonefinder_ft">',
//				'<div class="qzmod_tag">',
//					'<h5>智能分类：</h5>',
//					'<ul>',
//						'<li><a class="icon_blog current" href="#">日志</a></li>',
//						'<li><a class="icon_photo" href="#">相册</a></li>',
//						'<li><a class="icon_music" href="#">音乐</a></li>',
//						'<li><a class="icon_tweet" href="#">说说</a></li>',
//					'</ul>',
//				'</div>',
//			'</div>',
			'<div class="mask"></div>',
			'<div class="popup_qzonefinder_folder" id="_finder_folder_list" style="top:170px;">',
				'<div class="qzmod_itemlist_inner">',
					'<div class="scroll">',
						'<div class="qzmod_itemlist" id="_finder_folder">',
//		'					',
						'</div>',
					'</div>',
				'</div>',
				'<div class="arrow_up" id="_finder_folder_arrow" style="left:594px;"></div>',
			'</div>',
		'</div>'
	];

	var div = document.createElement("div");
	div.innerHTML = component.join("")
	div.style.display="none";
//	div.style.cssText = "z-index : 999999; display:none; position:absolute;top:0;left:0;";
	document.body.appendChild(div);


	var suffix = "./qzf/";
	QZFL.css.insertCSSLink(suffix+"/qzonefinder.css");
	QZFL.imports([suffix+"/pojo.js", suffix+"/sniffer.js", suffix+"/item_hit.js", suffix+"/db.js", suffix+"/finder_edit.js"], function(){
		QZFL.imports(suffix+"/quik.js");
		QZONE.Finder.db.init();
		ItemFactory.init(QZONE.Finder.db.getFullList());
		QZONE.qzEvent.addEventListener("QZ_JUMP_ENTER_BASE_APP", function(){setTimeout(function(){
			QZONE.Finder.Sniffer.bootstrap();
		}), 3000});

		//从桌面拖动图片到web
		QZONE.Finder.file.dragIn('.popup_qzonefinder', function(name, imgBase64){
			ItemFactory.addItem({
				type: 1,
				title: name,
				img: imgBase64
			});
		});

		QZONE.Finder.Sniffer.bootstrap();
		console.info("Loaded OK.")
	});

	return {
		suffix : suffix,
		show : function(cb) {
			div.style.display = "";
			cb && cb();
		},
		hide : function(cb) {
			div.style.display = "none";
			cb && cb();
		},
		swap : function() {
			if (div.style.display=="none") {
				QZONE.Finder.Loader.show();
			} else {
				QZONE.Finder.Loader.hide();
			}
		}
	}
}();

